package yunwo.cn.yzstation.printer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

/**
 * Created by lao on 2017/8/6.
 */

public class PrintBroadcastReceiver extends BroadcastReceiver {

    private SharedPreferences mPrinterShare;
    private SharedPreferences.Editor mPrinteredit;

    @Override
    public void onReceive(Context context, Intent intent) {
        mPrinterShare = context.getSharedPreferences("printerstate", Context.MODE_PRIVATE);
        mPrinteredit = mPrinterShare.edit();
        boolean isPrint = intent.getBooleanExtra(YHBPrintService.Send_key_printing,false);
        String timeout = intent.getStringExtra("timeout");
        Log.e("接收广播", String.valueOf(isPrint));
        mPrinteredit.putBoolean("state", isPrint);
        mPrinteredit.commit();
        if (timeout.equals("timeout")) {
            Toast.makeText(context, "打印机连接超时", Toast.LENGTH_SHORT).show();
            return;
        }
        if (isPrint) {
            Toast.makeText(context, "开始打印", Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(context, "打印完成", Toast.LENGTH_SHORT).show();
        }
    }
}
